var app = getApp();
Page({

  /** 
   * 页面的初始数据
   */
  data: {
    xturl: app.myUlife.ulifeUrl +"/",
    imgUrls: [
      app.myUlife.ulifeUrl + '/wx/topimg2.jpg',
    ],//默认图片列表
    imgdefalut: app.myUlife.ulifeUrl + '/wx/topimg2.jpg',//默认图片
    bookbg: app.myUlife.ulifeUrl + '/wx/book_bg_img.png',//学生作品背景图片
   
    /*首页轮播start*/
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 1200,
    /*首页轮播end*/ 

    tjimagedefault: '/testimage/timg1.jpg',//默认教师推荐图片

    timgs:[
      app.myUlife.ulifeUrl + '/testimage/timg1.jpg',
      app.myUlife.ulifeUrl + '/testimage/timg2.jpg',
      app.myUlife.ulifeUrl + '/testimage/timg3.jpg',
      app.myUlife.ulifeUrl + '/testimage/timg4.jpg',
    ],

    tjimageUrls:[],//教师推荐
    yximageUrls: [],//优秀书籍
    scimageUrls: [],//诗词天地
    xszpimageUrls: [],//学生作品

    tjlength:0,
    yxlength: 0,
    sclength: 0,
    xszplength: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  

  },


  onShow: function (options) {
    //加载首页顶部图片加载
    this.getHomeData();
  },


  //加载首页顶部图片加载
  getHomeData: function (e) {
    var that = this;
    wx.request({
      url: app.myUlife.ulifeUrl + 'whome/getHomeData.html',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {

        //首页轮播图
        var imgUrls = [];
        var imgs = res.data.tops;
        for (var i = 0; i < imgs.length;i++){
          imgUrls.push(app.myUlife.ulifeUrl + imgs[i].PICURL);
        }
      
        //教师推荐
        var tjimageUrls = res.data.jstj;
        var tjlength = tjimageUrls.length;
        //优秀书籍
        var yximageUrls = res.data.jztj;
        var yxlength = yximageUrls.length;
        //诗词天地
        var scimageUrls = res.data.sctd;
        var sclength = scimageUrls.length;
        //学生作品
        var xszpimageUrls = res.data.zpyc;
        var xszplength = xszpimageUrls.length;

        that.setData({
          tjimageUrls: tjimageUrls, 
          yximageUrls: yximageUrls,
          scimageUrls: scimageUrls, 
          xszpimageUrls: xszpimageUrls, 
          imgUrls: imgUrls,

          tjlength: tjlength,
          yxlength: yxlength,
          sclength: sclength,
          xszplength: xszplength,
        })

      }
    })
  },  


  errorFunction: function (e) {
    if (e.type == "error") {
      var errorImgIndex = e.target.dataset.errorimg
      var imgUrls = this.data.imgUrls    　　　　　　　//将图片列表数据绑定到变量
      imgUrls[errorImgIndex] = this.data.imgdefalut //错误图片替换为默认图片
      this.setData({
        imgUrls: imgUrls
      })
    }
  },

  errormoretj: function (e) {
    if (e.type == "error") {
      var errorImgIndex = e.target.dataset.errorimg
      var tjimageUrls = this.data.tjimageUrls    　　　　　　　//将图片列表数据绑定到变量
      tjimageUrls[errorImgIndex].FM = this.data.tjimagedefault //错误图片替换为默认图片
      this.setData({
        tjimageUrls: tjimageUrls
      })
    }
  },

  errormoreYxtj: function (e) {
    if (e.type == "error") {
      var errorImgIndex = e.target.dataset.errorimg
      var yximageUrls = this.data.yximageUrls    　　　　　　　//将图片列表数据绑定到变量
      yximageUrls[errorImgIndex].FM = this.data.tjimagedefault //错误图片替换为默认图片
      this.setData({
        yximageUrls: yximageUrls
      })
    }
  },


  //查看书籍详情
  todetail(e) {
    var bid = e.currentTarget.dataset.bid;
    wx.navigateTo({
      url: '../../pages/bookDetail/bookDetail?bid=' + bid
    })
  },


  //查看书籍详情
  todetailyx(e) {
    console.log(e);
    var bid = e.currentTarget.dataset.bid;
    wx.navigateTo({
      url: '../../pages/bookDetail/bookDetail?bid=' + bid
    })
  },
 
  //查看学生原创详情
  toxsycdetail(e) {
    var ycid = e.currentTarget.dataset.ycid;
    wx.navigateTo({
      url: '../../pages/xsycdetail/xsycdetail?ycid=' + ycid
    })
  },
  

  //诗词天地 我的任务
  toTaskDetail(e) {
    var readid = e.currentTarget.dataset.readid;
    wx.navigateTo({
      url: '../../pages/task/poetryDetail/poetryDetail?readid=' + readid
    })
  },

})